<?php
	$alldatas = $this->getAlldatas();
	$source = $alldatas['source'];
	$atridarray = array();
?>
<?php
	if($source=='upload'):
		$attributes = $alldatas['attributedetails'];
		$category = $alldatas['category'];
		$bookscategories = $alldatas['bookscategories']; 
			foreach($attributes as $alldata):
	            $resource = Mage::getSingleton('core/resource');
	            $readConnection = $resource->getConnection('core_read');
	            $filldata= $readConnection->fetchAll("SELECT * FROM ".Mage::getConfig()->getTablePrefix()."marketcategory_autofill where field_id='".$alldata['fieldset']."'");
	            $code=$alldata['attribute_code'];
	            if($alldata['visible']=='Yes'):
	                array_push($atridarray, $alldata['attribute_id']);
	                if($alldata['fieldsetid']!='4'):
	                    if($alldata['inputtype']=='Text'):
	                        if($alldata['required']==1): ?>                        
	                           	<li class='autoattibuteli'>
	                           		<h1 class='topic'><?php echo $alldata['frontend_label'] ?></h1>
	                           		<span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
								   	<?php 
								   	if(!in_array($category, $bookscategories))
									{ 
									?>
									   	<div class='autopopdiv'>
											<select class='droptextselect chosen-select allow_additem chzn-done' name="<?php echo $alldata['attribute_code'] ?>" id="droptext<?php echo $alldata['attribute_code'] ?>">
												<option></option>";
												<?php foreach ($filldata as $fill): ?>											
													<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
												<?php endforeach; ?>
											</select>
										</div>
								</li>
	                         	<?php 
	                         		}
	                            	else
	                            	{ 
	                            ?>
	                              		<input name="<?php echo $alldata['attribute_code'] ?>" class='prodinput new required-entry' placeholder="Enter <?php echo $alldata['frontend_label'] ?>" onblur='modify(this.value,this.id)' onkeyup="autofill(this.value,this.id,<?php echo $alldata['fieldset'] ?>)" type='text' id="<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>" />
								</li>
	                        	<?php    
	                        		}                        
	                        else: ?>                         
							<li class='autoattibuteli'>
								<h1 class='topic'><?php echo $alldata['frontend_label'] ?></h1>
	                         	<?php 
	                         	if(!in_array($category, $bookscategories)): 
	                         	?>
									<div class='autopopdiv'>
	                              		<select class='droptextselect chosen-select allow_additem' name="<?php echo $alldata['attribute_code'] ?>" id="droptext<?php echo $alldata['attribute_code'] ?>">
											<option></option>
											<?php  
											foreach ($filldata as $fill): 
											?>									
												<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
											<?php 
											endforeach; 
											?>
	                              		</select>
	                            	</div>
	                        </li>
	                        <?php 
	                        	else: 
	                        ?>
									<input class='prodinput new' placeholder="Enter<?php echo $alldata['frontend_label'] ?>" type='text' id="<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>" />
	                        </li>
	                        <?php 
	                        endif;
	                    endif;     
	                    elseif($alldata['inputtype']=='Dropdown'):
	                        if($alldata['required']==1): ?>
	                            <li class="autoattibuteli">
									<h1 class='topic'><?php echo $alldata['frontend_label'] ?></h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
									<div class='autopopdiv'>
										<select class='required-entry chosen-select chzn-done disablesrch' id="droptext<?php echo $alldata['attribute_code'] ?>" atrid="<?php echo $alldata['attribute_id'] ?>" name="<?php $alldata['attribute_code'] ?>">
											<option ></option>
											<?php foreach ($filldata as $fill): ?>                        
												<option value="<?php echo $fill['values'] ?>"><?php echo $fill['values'] ?></option>
											<?php endforeach; ?>
										</select>
							 <?php else: ?>
	                         <li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?></h1>
								<div class='autopopdiv'>
									<select class='chosen-select disablesrch' id="droptext<?php echo $alldata['attribute_code'] ?>" atrid="<?php echo $alldata['attribute_id'] ?>" name="<?php echo $alldata['attribute_code'] ?>">
										<option ></option>
										<?php  foreach ($filldata as $fill): ?>
											<option value="<?php $fill['values'] ?>"><?php echo $fill['values'] ?></option>
										<?php endforeach; ?>
									</select>
								</div>
							 </li>
	                      <?php endif; ?>						
	                    <?php endif; ?>
							<li class='autofillerrmsg'><span class="errmsg-droptext<?php echo $alldata['attribute_code'] ?>"></span></li>
	               <?php endif;
	            endif;
	        endforeach; 
	else:
		$category = $alldatas['category'];
		$productid = $alldatas['productid'];
		$attributedetails = $alldatas['attributedetails'];
		$bookscategories = $alldatas['bookscategories'];
		if($productid!='new'):
			
			#$codearray = $alldatas['codearray'];
			$idarray = $alldatas['idarray'];
			$loadproduct = $product = Mage::getModel('catalog/product');
			$loadproduct = $product->load($productid);
			foreach ($attributedetails as $alldata):
				$resource = Mage::getSingleton('core/resource');
				$readConnection = $resource->getConnection('core_read');
				$filldata= $readConnection->fetchAll("SELECT * FROM ".Mage::getConfig()->getTablePrefix()."marketcategory_autofill where field_id='".$alldata['fieldset']."'");
				if($alldata['visible']=='Yes'):
					if(!in_array($alldata['attribute_code'], $codearray)):
						array_push($idarray, $alldata['attribute_id']);
						if($alldata['fieldsetid']!='4'):
							if($alldata['inputtype']=='Text'):
								$code=$alldata['attribute_code'];
								$attribute = Mage::getModel('eav/entity_attribute')->load($alldata['attribute_id']);
								$input_type = $attribute->getFrontendInput();
								if($input_type == 'text'):
									if($alldata['required']=='1'): ?>
										<li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
										<?php 
											if(!in_array($category, $bookscategories)): ?>
											<div class='autopopdiv'>
												<select class='chosen-select droptextselect allow_additem chzn-done' name="<?php echo $alldata['attribute_code'] ?>" id="droptext<?php echo $alldata['attribute_code'] ?>">
													<option selected value="<?php echo $loadproduct->$alldata['attribute_code'] ?>" code="<?php echo $code ?>"> <?php echo $loadproduct->$alldata['attribute_code'] ?> </option>
												<?php 
													foreach ($filldata as $fill):
														if($loadproduct->$alldata['attribute_code']!=$fill['values']): ?>
															<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
														<?php endif;
													endforeach; 
												?>
												</select>
											</div>
										</li>
									<?php else: ?>
											<input placeholder=" Enter <?php echo $alldata['frontend_label'] ?>" class='prodinput new required-entry' type='text' value="<?php echo $loadproduct->$alldata['attribute_code'] ?>" id="<?php echo $alldata['attribute_code'] ?>"  style="margin-right:81px" name="<?php echo $alldata['attribute_code'] ?>" />
											
										</li>
									<?php endif;
									else: ?>
										<li class='autoattibuteli'><h1 class='topic'> <?php echo $alldata['frontend_label'] ?> </h1>
										<?php if(!in_array($category,$bookscategories)): ?>
											<div class='autopopdiv'> <select class='chosen-select allow_additem droptextselect' name="<?php echo $alldata['attribute_code'] ?>" id="droptext<?php echo $alldata['attribute_code'] ?>">
												<option selected value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" code="<?php echo $code ?>"><?php echo $loadproduct->$alldata['attribute_code'] ?></option>
											<?php foreach ($filldata as $fill):
												if($loadproduct->$alldata['attribute_code']!=$fill['values']): ?>
													<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
												<?php endif;	
											endforeach; ?>
											</select></div></li>
										<?php else: ?>
											<input placeholder="  Enter <?php echo $alldata['frontend_label'] ?>" class='prodinput new' type='text' value="<?php echo $loadproduct->$alldata['attribute_code'] ?>" id="<?php echo $alldata['attribute_code'] ?>" style="margin-right:81px" name="<?php echo $alldata['attribute_code'] ?>" />
											</div></li>
										<?php endif;
									endif;	
								else:
								if($alldata['required']=='1'): ?>
									<li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
									<?php if(!in_array($category, $bookscategories)): ?>
										<div class='autopopdiv'>
											<select name="<?php echo $alldata['attribute_code'] ?>" class='droptextselect allow_additem chosen-select chzn-done' id="droptext<?php echo $alldata['attribute_code'] ?>">
												<option selected value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" code="<?php echo $code ?>"><?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?></option>
										<?php foreach ($filldata as $fill):
											if($loadproduct->getAttributeText($alldata['attribute_code'])!=$fill['values']): ?>
												<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>" ><?php echo $fill['values'] ?></option>
											<?php endif;
										endforeach; ?>
										</select></div></li>
									<?php else: ?>
										<div class='autopopdiv'><input class='prodinput new required-entry' type='text' value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" id="<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>" />
										</div></li>
									<?php endif;
								else: ?>
									<li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?></h1>
									<?php if(!in_array($category, $bookscategories)): ?>
										<div class='autopopdiv'>
										<select name="<?php echo $alldata['attribute_code'] ?>" class='droptextselect chosen-select allow_additem' id="droptext<?php echo $alldata['attribute_code'] ?>">
											<option selected value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" code="<?php echo $code ?>" ><?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?></option>
										<?php foreach ($filldata as $fill):
											if($loadproduct->getAttributeText($alldata['attribute_code'])!=$fill['values']): ?>
												<option value="<?php echo $fill['values'] ?>" code="<?php echo $code?>"><?php echo $fill['values'] ?></option>
											<?php endif;
										endforeach; ?>
										</select></div></li>
									<?php else: ?>
										<div class='autopopdiv'><input class='prodinput new' onblur='modify(this.value,this.id)' onkeyup='autofill(this.value,this.id,"<?php echo $alldata['fieldset'] ?>")' type='text' value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" id="<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>" />
										</div></li>
									<?php endif;
								endif;	
							endif;
						elseif($alldata['inputtype']=='Dropdown'):
							if($alldata['required']=='1'): ?>
								<li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
									<div class='autopopdiv'> <select class='required-entry chosen-select chzn-done' id="droptext<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>">
								<?php $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$alldata['attribute_code']);
								$pre_selected = $loadproduct->getAttributeText($alldata['attribute_code']); ?>
								<option selected value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" code="<?php echo $code ?>" ><?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?></option>
								<?php foreach ($filldata as $fill):
									if($pre_selected !=$fill['values']): ?>
										<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
									<?php endif;
								endforeach;?>
								</select></div></li>
								</select></div></li>
							<?php else: ?>
								<li class='autoattibuteli'><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1>
								<div class='autopopdiv'><select id="droptext<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>">
								<?php $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$alldata['attribute_code']);
								$pre_selected = $loadproduct->getAttributeText($alldata['attribute_code']); ?>
								<option selected value="<?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?>" code="<?php echo $code ?>"><?php echo $loadproduct->getAttributeText($alldata['attribute_code']) ?></option>
								<?php foreach ($filldata as $fill):
									if($pre_selected!=$fill['values']): ?>
										<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
									<?php endif;
								endforeach; ?>
								</select></div></li>
							<?php endif;
						endif; ?>
						<li class='autofillerrmsg'><span class="errmsg-droptext<?php echo $alldata['attribute_code']?>"></span></li>
					<?php endif;
				endif;
			endif;
		endforeach;
		$ids=implode(",", $idarray); ?>
		<li><input name='otherids' type='hidden' value="<?php echo $ids ?>" /></li>
	<?php else: ?>
		<?php 
		$idsarray = $alldatas['idsarray'];
		foreach ($attributedetails as $alldata):
        $resource = Mage::getSingleton('core/resource');
		$readConnection = $resource->getConnection('core_read');
		$filldata= $readConnection->fetchAll("SELECT * FROM ".Mage::getConfig()->getTablePrefix()."marketcategory_autofill where field_id='".$alldata['fieldset']."'");
        if($alldata['visible']=='Yes'):
     		$code=$alldata['attribute_code'];
     		array_push($idsarray, $alldata['attribute_id']);
     		if($alldata['fieldsetid']!='4'):
				if($alldata['inputtype']=='Text'):
	     			if($alldata['required']=='1'): ?>
						<li class='autoattibuteli' id="<?php echo $alldata['attribute_id'] ?>"><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
						<?php if(!in_array($category, $bookscategories)): ?>
							<div class='autopopdiv'>
							<select class='droptextselect chosen-select chzn-done allow_additem' name="<?php echo $alldata['attribute_code'] ?>" id="droptext<?php echo $alldata['attribute_code'] ?>">
							<option></option>
							<?php foreach ($filldata as $fill): ?>
	     					 	<option value="<?php echo $fill['values']?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
	     					<?php endforeach; ?>
     						</select></div></li>
						<?php else: ?>
	     						<div class='autopopdiv'><input type='text' class='prodinput new required-entry' value='' atrid="<?php echo $alldata['attribute_id'] ?>" id="<?php echo $alldata['attribute_code'] ?>" name="<?php echo $alldata['attribute_code'] ?>" onkeyup='autofill(this.value,this.id,"<?php echo $alldata['fieldset'] ?>")'/>
	     						</div></li>
	     				<?php endif;						
					endif;
     			else:
 					if($alldata['required']=='1'): ?>
						<li class='autoattibuteli' id="<?php echo $alldata['attribute_id'] ?>"><h1 for="<?php echo $alldata['attribute_code'] ?>" class='topic'><?php echo $alldata['frontend_label'] ?></h1><span class='required starimp'>&nbsp;&nbsp;&nbsp;&nbsp;</span>
						<div class='autopopdiv'><select class='required-entry chosen-select chzn-done' id="droptext<?php echo $alldata['attribute_code'] ?>" atrid="<?php echo $alldata['attribute_id'] ?>" name="<?php echo $alldata['attribute_code'] ?>">
					    <option ></option>
				        <?php foreach ($filldata as $fill): ?>
				             <option value="<?php echo $fill['values'] ?>"><?php echo $fill['values'] ?></option>
				        <?php endforeach; ?>
				        </select></div></li>
					<?php endif;
 				endif;
		
					if(!in_array($alldata['attribute_id'],$usedattrid)):
						if($alldata['required']=='2'):
     					if($alldata['inputtype']=='Text'): ?>
 							<li class='autoattibuteli' id="<?php echo $alldata['attribute_id'] ?>" ><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1>
		 					<?php if(!in_array($category, $bookscategories)): ?>
		 						<div class='autopopdiv'><select name="<?php echo $alldata['attribute_code'] ?>" class='droptextselect chosen-select allow_additem' id="droptext<?php echo $alldata['attribute_code'] ?>">
		     					<option></option>
		     					<?php foreach ($filldata as $fill): ?>
									<option value="<?php echo $fill['values'] ?>" code="<?php echo $code ?>"><?php echo $fill['values'] ?></option>
		     					<?php endforeach; ?>
		     					</select></div></li>
		     				<?php else: ?>
		     					<div class='autopopdiv'><input type='text' class='prodinput' value='' name="<?php echo $alldata['attribute_code'] ?>"/>
		     					</div></li>
		     				<?php endif; ?>
						<?php else: ?>
	     					<li class='autoattibuteli' id="<?php echo $alldata['attribute_id'] ?>"><h1 class='topic'><?php echo $alldata['frontend_label'] ?> </h1>
	     					<div class='autopopdiv'><select id="droptext<?php echo $alldata['attribute_code'] ?>" class='chosen-select' atrid="<php echo $alldata['attribute_id'] ?>" name="<?php echo $alldata['attribute_code'] ?>">
			 			    <option ></option>
					        <?php foreach ($filldata as $fill): ?>
					              <option value="<?php echo $fill['values'] ?>"><?php echo $fill['values'] ?></option>
					        <?php endforeach; ?>
					        </select></div></li>
					    <?php endif;							
				    endif;
				endif; ?>
					<li class='autofillerrmsg'><span class="errmsg-droptext<?php echo $alldata['attribute_code']?>"></span></li>
	    	<?php endif;
			endif;
		endforeach;
		$idss=implode(",", $idsarray); ?>
 		<li><input name='otherids' type='hidden' value="<?php echo $idss ?>" /></li>
 	<?php endif; ?>
<?php endif; ?>
